package com.xqboss.web.controller.system;

import com.xqboss.apps.domain.sys.SysRechargeAmountConfig;
import com.xqboss.apps.dto.system.EditRechargeAmountConfigDto;
import com.xqboss.apps.service.sys.SysRechargeAmountConfigService;
import com.xqboss.apps.util.mh.BeanCopierUtil;
import com.xqboss.common.annotation.Log;
import com.xqboss.common.core.controller.BaseController;
import com.xqboss.common.core.domain.R;
import com.xqboss.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author Trent
 * @date 2023/8/22
 */

@Api(tags = {"系统-充值配置"})
@Slf4j
@RestController("WebRechargeConfigController")
@RequestMapping("/web/config/recharge")
public class RechargeConfigController extends BaseController {

    @Autowired
    private SysRechargeAmountConfigService rechargeAmountConfigService;

    /**
     * 获取充值列表
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('web:config:recharge:list')")
    @ApiOperation("获取充值列表")
    @PostMapping("list")
    public R<List<SysRechargeAmountConfig>> rechargeList() {
        List<SysRechargeAmountConfig> list = rechargeAmountConfigService.list();
        return R.ok(list);
    }

    @PreAuthorize("@ss.hasPermi('web:config:recharge:del')")
    @ApiOperation("删除充值")
    @DeleteMapping("del/{id}")
    @Log(title = "充值配置", businessType = BusinessType.DELETE)
    public R del(@PathVariable("id")
                 @ApiParam(value = "充值配置ID", required = true)
                 @NotNull(message = "请输入充值配置ID")
                 Long id){
        rechargeAmountConfigService.removeById(id);
        return R.ok();
    }

    @PreAuthorize("@ss.hasPermi('web:config:recharge:edit')")
    @ApiOperation("修改充值")
    @PutMapping("edit")
    @Log(title = "充值配置", businessType = BusinessType.UPDATE)
    public R edit(@Validated @RequestBody EditRechargeAmountConfigDto params){
        SysRechargeAmountConfig config = BeanCopierUtil.copy(params, SysRechargeAmountConfig.class);
        rechargeAmountConfigService.updateById(config);
        return R.ok();
    }

    @PreAuthorize("@ss.hasPermi('web:config:recharge:add')")
    @ApiOperation("添加充值")
    @PostMapping("add")
    @Log(title = "充值配置", businessType = BusinessType.INSERT)
    public R add(@Validated @RequestBody EditRechargeAmountConfigDto params){
        SysRechargeAmountConfig config = BeanCopierUtil.copy(params, SysRechargeAmountConfig.class);
        config.setId(null);
        rechargeAmountConfigService.save(config);
        return R.ok();
    }
}
